package com.hzsai.kafka;

import com.hzsai.schedule.PushServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @author: hzsai
 * @date : 2020/3/25
 * usage:
 **/
@Component
public class KafkaReceiver {

    @Autowired
    private PushServer pushServer;

    private static final Logger logger = LoggerFactory.getLogger(KafkaReceiver.class);

    @KafkaListener(id="test-group", topics = {"test-topic"})
    public void receive(String message) {
        logger.info("接收到kafka数据：{}", message);
    }

    @KafkaListener(id = "default-group", topics = {"cloud-live-topic"})
    public void receiveGroupDefault(String message) {
        logger.info("接收到kafka数据:{}", message);
        logger.info("正将数据推送到客户端...");

        pushServer.start(message);
    }
}
